package com.guigu.community.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.community.mapper.MerchantsMapper;
import com.guigu.community.pojo.Merchants;
import com.guigu.community.service.MerchantsService;
import com.guigu.community.vo.MerchantsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MerchantsServiceImpl extends ServiceImpl<MerchantsMapper, Merchants> implements MerchantsService {
    @Autowired
    private MerchantsMapper merchantsMapper;
    @Override
    public PageInfo<Merchants> queryMerchants(Integer pageNo, Integer pageSize, MerchantsVo vo) {
        PageHelper.startPage(pageNo,pageSize);
        List<Merchants> merchants = merchantsMapper.selectMerchants(vo);
        PageInfo<Merchants> merchantsPageInfo = new PageInfo<>(merchants);
        return merchantsPageInfo;
    }

    @Override
    public PageInfo<Merchants> selectByVo(Integer pageNo, Integer pageSize, MerchantsVo vo) {
        PageHelper.startPage(pageNo, pageSize);
        // 修改为调用返回 List 的方法
        List<Merchants> merchants = merchantsMapper.selectMerchantsCount(vo);
        PageInfo<Merchants> merchantsPageInfo = new PageInfo<>(merchants);
        return merchantsPageInfo;
    }

    @Override
    public boolean approveMerchant(Integer merchantId) {
        Merchants merchants = new Merchants();
        merchants.setMerchantId(merchantId);
        merchants.setStatus(1); // 设置商户状态为已审核
        merchants.setIsBusiness(1); // 设置营业状态为营业
        return this.updateById(merchants);
    }

    @Override
    public boolean rejectMerchant(Integer merchantId) {
        Merchants merchants = new Merchants();
        merchants.setMerchantId(merchantId);
        merchants.setStatus(2); // 设置商户状态为审核拒绝
        return this.updateById(merchants);
    }

    @Override
    public PageInfo<Merchants> selectByVo2(Integer pageNo, Integer pageSize, MerchantsVo vo) {
        PageHelper.startPage(pageNo,pageSize);
        List<Merchants> merchants = merchantsMapper.selectByVo2(vo);
        PageInfo<Merchants> merchantsPageInfo = new PageInfo<>(merchants);
        return merchantsPageInfo;
    }
}
